
package com.ryan.notify.ad;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;

import com.ryan.notify.ad.impl.AdmobAd;
import com.ryan.notify.ad.impl.AdwoAd;
import com.ryan.notify.ad.impl.AiradAd;
import com.ryan.notify.ad.impl.BaiduAd;
import com.ryan.notify.ad.impl.DianJoyAd;
import com.ryan.notify.ad.impl.DianruAd;
import com.ryan.notify.ad.impl.DomobAd;
import com.ryan.notify.ad.impl.DtnAd;
import com.ryan.notify.ad.impl.JuziAd;
import com.ryan.notify.ad.impl.KuguoAd;
import com.ryan.notify.ad.impl.LmAd;
import com.ryan.notify.ad.impl.MadhouseAd;
import com.ryan.notify.ad.impl.MobclixAd;
import com.ryan.notify.ad.impl.TencentAd;
import com.ryan.notify.ad.impl.VponAd;
import com.ryan.notify.ad.impl.WapsAd;
import com.ryan.notify.ad.impl.WiyunAd;
import com.ryan.notify.ad.impl.WoobooAd;
import com.ryan.notify.ad.impl.WqmobileAd;
import com.ryan.notify.ad.impl.YoumiAd;
import com.ryan.notify.ad.model.AdResult;

public class AdProcess {

    private static AdProcess sington;

    private List<IAd> adList;

    private AdProcess() {
        adList = new ArrayList<IAd>();
        adList.add(new AdmobAd());
        adList.add(new AdwoAd());
        adList.add(new AiradAd());
        adList.add(new BaiduAd());
        adList.add(new DianruAd());
        adList.add(new DomobAd());
        adList.add(new DtnAd());
        adList.add(new JuziAd());
        adList.add(new LmAd());
        adList.add(new MadhouseAd());
        adList.add(new VponAd());
        adList.add(new WapsAd());
        adList.add(new WiyunAd());
        adList.add(new WoobooAd());
        adList.add(new YoumiAd());
        adList.add(new WqmobileAd());
        adList.add(new MobclixAd());
        adList.add(new KuguoAd());
        adList.add(new DianJoyAd());
        adList.add(new TencentAd());
    }

    public static AdProcess getInstance() {
        if (sington == null)
            return new AdProcess();
        else
            return sington;
    }

    public AdResult check(Context ctx, String pkg) {
        try {
            Context pkgCtx = ctx.createPackageContext(pkg, Context.CONTEXT_IGNORE_SECURITY|Context.CONTEXT_INCLUDE_CODE);
            for (IAd ad : adList) {
                AdResult checkResult = ad.check(pkgCtx);
                if(checkResult.isAd()){
                    return checkResult;
                }
            }
        } catch (NameNotFoundException e) {
//            LogUtil.e("E", "NameNotFoundException ", e);
        }
        return new AdResult(pkg);
    }

}
